package com.ctgu.computer.controller.topic;


import com.ctgu.computer.annotation.FillNowTime;
import com.ctgu.computer.common.SuccessMessage;
import com.ctgu.computer.domain.dto.NoticeAddDTO;
import com.ctgu.computer.domain.dto.NoticePageDTO;
import com.ctgu.computer.domain.result.PageResult;
import com.ctgu.computer.domain.result.Result;
import com.ctgu.computer.domain.vo.NoticeVO;
import com.ctgu.computer.service.NoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sys/notice")
@RequiredArgsConstructor
@Tag(name = "公告相关接口")
public class NoticeController {

    private final NoticeService noticeService;


    @Operation(summary = "新增公告")
    @PostMapping("/add")
    public Result addNotice(@RequestBody NoticeAddDTO noticeAddDTO){
        noticeService.addNotice(noticeAddDTO);
        return Result.success(SuccessMessage.ADD_SUCCESS,null);
    }

    @Operation(summary = "分页查询所有公告")
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody NoticePageDTO noticePageDTO){
        PageResult pageResult = noticeService.page(noticePageDTO);
        System.out.println("分页查询公告"+pageResult);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据管理员id查询公告")
    @GetMapping("/select/{adminId}")
    public Result<List<NoticeVO>> getById(@PathVariable Integer adminId){
        return Result.success(noticeService.getById(adminId));
    }

    @Operation(summary = "删除公告")
    @GetMapping("/delete/{noticeId}")
    public Result deleteNotice(@PathVariable Integer noticeId){
        noticeService.removeById(noticeId);
        return Result.success(SuccessMessage.DELETE_SUCCESS,null);

    }

    @Operation(summary = "更新公告")
    @PostMapping("/update")
    public Result updateNoticeById(@RequestBody NoticeAddDTO noticeAddDTO){
        noticeService.updateById(noticeAddDTO);
        return Result.success(SuccessMessage.UPDATE_SUCCESS,null);
    }

}
